package com.ktjiaoyu.springsecuritydemo.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {

    @GetMapping("/tologin")
    public String toLogin() {
        return "login";
    }

/*    @PostMapping("/doLogin")
    public String login() {
        System.out.println("执行登录方法");
        return "main";
    }*/

    // 负责登录成功后跳转到主页面
    @RequestMapping("/toMain")
    public String toMain() {
        return "main";
    }

    // 负责登录失败后跳转到失败页面
    @RequestMapping("/toError")
    public String toError() {
        return "error";
    }

    // 负责跳转到main1.html
    //@Secured("ROLE_abc")
    @PreAuthorize("hasRole('abc')")
    @GetMapping("/toMain1")
    public String toMain1() {
        return "main1";
    }

    // 负责跳转到demo.html页面
    @RequestMapping("/demo")
    public String demo() {
        return "demo";
    }
}